import { useState } from "react";

export const useObject = (initialState) => {
  const [state, setState] = useState(initialState);

  const update = (newState) => {
    if (newState && typeof newState === "object") {
      setState((prevState) => ({
        ...prevState,
        ...newState,
      }));
    } else {
      throw Error("property is not a object");
    }
  };

  const clear = setState({});

  return [state, update, setState, clear];
};
